$(document).keyup(function (event) {
    if (event.keyCode === 13) {
        $("#btn").click();
        $("#btn_reg").click();
    }
});
$(function () {

    // $("#username").blur(checkUsername);
    // $("#password").blur(checkPassword);
    // $("#password2").blur(checkPassword2);
    // $("#name").blur(checkName);
    // $("#email").blur(checkEmail);
    // $("#telephone").blur(checkPhone);
    // $("#checkCode").blur(checkCheck);

    $("#btn").click(function () {
        var checkCode = $("#checkCode").val();
        var username = $("#username").val();
        var password = $("#password").val();


        $.ajax({
            url: "/user/userLoginCheck",
            type: "PUT",
            data: {
                username: username,
                password: password,
                checkCode:checkCode,
            },
            success: function (data) {
                if(data.flag){
                    window.location = "/user/index";
                }else {
                    alert(data.message);
                }
            },
            error: function (e) {
                alert("error!");
            }
        })

    });

    $("#btn_reg").click(function () {
        var username = $("#username").val();
        var password = $("#password").val();
        var name = $("#name").val();
        var email = $("#email").val();
        var phone = $("#phone").val();
        var qq = $("#qq").val();
        var address = $("#address").val();
        var securityQuestion = $("#securityQuestion").val();
        var answer = $("#answer").val();
        $.ajax({
            url: "/user/userRegisterCheck",
            type: "PUT",
            data: {
                username:username,
                password:password,
                name:name,
                email:email,
                phone:phone,
                qq:qq,
                address:address,
                securityQuestion:securityQuestion,
                answer:answer,
            },
            success: function (resultInfo) {
                if(resultInfo.flag){
                    alert(resultInfo.message);
                    setTimeout('window.location = "/user/login"',3000);
                }else {
                    alert(resultInfo.message);
                }
            },
            error: function (e) {
                alert("error!");
            }
        });
    });

});